package com.example.cathouse;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

//singleton 单个实例
//synchronized 保证多线程同时申请INSTANCE时不会碰撞
@Database(entities = {Cat.class}, version = 2, exportSchema = false)
public abstract class CatDatabase extends RoomDatabase {
    private static CatDatabase INSTANCE;

    static synchronized CatDatabase getDatabase(Context context) {
        if (INSTANCE == null) {
            INSTANCE = Room.databaseBuilder(context.getApplicationContext(), CatDatabase.class, "cat_database")
                    .build();
        }
        return INSTANCE;
    }

    public abstract CatDao getCatDao();

}
